
import 'package:flutter/widgets.dart';

class ListTool {
  static List<V> generateOrEmpty<T, V>(List<T>? items, List<V> empty(), V each(T item)) {
    if (items == null) {
      return empty();
    }
    return List.generate(items.length, (index) => each(items[index]));
  }

  static List<T> insertGap<T>(List<T> items, T gap) {
    if (items.length == 0) {
      return items;
    }

    var newList = List<T>.empty(growable: true);
    items.forEach((element) {
      newList.add(element);
      newList.add(gap);
    });
    newList.removeLast();
    return newList;
  }
}